package com.jy.api.service.impl;

import com.jy.api.dao.StockReceiptDao;
import com.jy.api.domain.StockChangeReason;
import com.jy.api.domain.StockReceipt;
import com.jy.api.domain.StockType;
import com.jy.api.service.StockReceiptSerivce;
import com.jy.api.signUpReq.stock.InventoryInReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2018/7/14.
 */
@Slf4j
@Service
public class StockReceiptSerivceImpl implements StockReceiptSerivce {

    @Autowired
    private StockReceiptDao stockReceiptDao;

    @Override
    @Transactional
    public StockReceipt save(InventoryInReq inReq) {
        java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
        if (!inReq.getStockSource().equals(StockChangeReason.INNER_IN)) {
            StockReceipt stockReceipt = new StockReceipt(inReq, StockType.STOCK_IN);
            StockReceipt s = stockReceiptDao.save(stockReceipt);
            return s;
        } else {
            return null;
        }
    }

    @Override
    @Transactional
    public StockReceipt out(InventoryInReq inReq) {
        //判断是否是内部出库，不是的话 就生成receipt
        if (!inReq.getStockSource().equals(StockChangeReason.INNER_OUT)) {
            StockReceipt stockReceipt = new StockReceipt(inReq, StockType.STOCK_OUT);
            StockReceipt s = stockReceiptDao.save(stockReceipt);
            return s;
        } else {
            return null;
        }
    }
}
